﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.MainModule.Entities;

namespace Application.MainModule.DinnerManagement
{
    public static class DinnerMapping
    {
        public static Dinners ToDinner(this DinnerDTO dinnerDTO)
        {
            if (dinnerDTO == null)
            {
                return null;
            }
            return new Dinners()
                       {
                           DinnerID = dinnerDTO.DinnerID,
                           Title = dinnerDTO.Title,
                           Address = dinnerDTO.Address,
                           EventDate = dinnerDTO.EventDate,
                           Description = dinnerDTO.Description,
                           HostedBy = dinnerDTO.HostedBy,
                           HostedById = dinnerDTO.HostedById,
                           ContactPhone = dinnerDTO.ContactPhone,
                           Country = dinnerDTO.Country,
                           Latitude = dinnerDTO.Latitude,
                           Longitude = dinnerDTO.Longitude,
                           RSVPs = dinnerDTO.RsvpDtos.ToRVSPList()
                       };

        }

        public static DinnerDTO ToDinnerDTO(this Dinners dinner)
        {
            if (dinner == null)
            {
                return null;
            }
            return new DinnerDTO()
            {
                DinnerID = dinner.DinnerID,
                Title = dinner.Title,
                Address = dinner.Address,
                EventDate = dinner.EventDate,
                Description = dinner.Description,
                HostedBy = dinner.HostedBy,
                HostedById = dinner.HostedById,
                ContactPhone = dinner.ContactPhone,
                Country = dinner.Country,
                Latitude = dinner.Latitude,
                Longitude = dinner.Longitude,
                RsvpDtos = dinner.RSVPs.ToRVSPDTOList()
            };
        }

        public static RSVPs ToRVSP(this RsvpDTO rsvpDTO)
        {
            if (rsvpDTO == null)
            {
                return null;
            }
            return new RSVPs()
            {
               DinnerID = rsvpDTO.DinnerID,
               AttendeeName = rsvpDTO.AttendeeName,
               AttendeeNameId = rsvpDTO.AttendeeNameId,
               RsvpID = rsvpDTO.RsvpID
            };
        }
        public static RsvpDTO ToRVSPDTO(this RSVPs rsvp)
        {
            if (rsvp == null)
            {
                return null;
            }
            return new RsvpDTO()
            {
                DinnerID = rsvp.DinnerID,
                AttendeeName = rsvp.AttendeeName,
                AttendeeNameId = rsvp.AttendeeNameId,
                RsvpID = rsvp.RsvpID
            };
        }

        public static List<RSVPs> ToRVSPList(this List<RsvpDTO> rsvpDTOs)
        {
            if (rsvpDTOs == null)
            {
                return null;
            }
            return rsvpDTOs.Select(dto => dto.ToRVSP()).ToList();
        }

        public static List<RsvpDTO> ToRVSPDTOList(this ICollection<RSVPs> rsvps)
        {
            if (rsvps == null)
            {
                return null;
            }
            return rsvps.Select(dto => dto.ToRVSPDTO()).ToList();
        }
    }
}
